zk.afterLoad("zul.inp",function() {

    /**
     *  Error box
     */
    zk.$package("kmc").Errorbox = zk.$extends(zul.inp.Errorbox, {
        open: function () {
            // Reset postion
            arguments[2] = this._getPosition();

            // Call supper
            this.$supers('open', arguments);
        },

        _getPosition: function() {
            var n = this.$n(),
                nDim = zk(n).dimension(true),
                pDim = zk(this.parent.$n()).dimension(true),
                wDim = zk(zk(n).vparentNode(true)).dimension(true);

            var p1 = "after", p2="start"; // Default is after_start

            if (pDim.left + nDim.width > wDim.width) {
                p2 = "end";
            }
            if (pDim.top + pDim.height + nDim.height > wDim.height) {
                p1 = "before";
            }
            return p1 + "_" + p2;
        }
    });

    var showError_ = function(msg) {
        var eb = new kmc.Errorbox();
        eb.show(this, msg);
        return eb;
    }

    zul.inp.Textbox.prototype.showError_ = showError_;
    zul.inp.Intbox.prototype.showError_ = showError_;
    zul.inp.Longbox.prototype.showError_ = showError_;
    zul.inp.Doublebox.prototype.showError_ = showError_;
    zul.inp.Decimalbox.prototype.showError_ = showError_;
    zul.inp.Combobox.prototype.showError_ = showError_;
    zul.inp.Bandbox.prototype.showError_ = showError_;
    zul.inp.Spinner.prototype.showError_ = showError_;
    zul.inp.ComboWidget.prototype.showError_ = showError_;
    zul.inp.FormatWidget.prototype.showError_ = showError_;
});